//app.js
App({
  onLaunch: function (options) {
    // 展示本地存储能力
    let user_id =0 

    try {
      var value = wx.getStorageSync('user_id')
      console.log(value)
      if (value) {
        user_id=value
      }
    } catch (e) {
      console.log('no_user_id')
    }
    console.log(user_id)
    console.log(options)
 
    console.log(333,options.query.user_id)
    if (options.query.user_id==undefined){
      if (options.query.scene) {
        let scene = decodeURIComponent(options.query.scene);
        //&是我们定义的参数链接方式
        user_id = scene.split("&")[0];
        console.log(user_id)
        this.globalData.workshop_id = scene.split('&')[1];
      }
    }else{
      user_id = options.query.user_id
    }
    console.log(user_id)
    try {
      wx.setStorageSync('user_id', user_id)
    } catch (e) { 
      console.log('储存出错')
    }
    //推荐个人
    wx.request({
      url: this.globalData.apiurl + "agent/" + user_id,
      /*  header: {
          "Authorization": "bearer " + app.globalData.access_token
        },*/
      method: 'get',
      success: res => {
        if (res.data.code == 0) {
          this.globalData.userInfo= res.data.data
          if (this.emptyUserInfoCallback) {
            this.emptyUserInfoCallback(this.globalData.userInfo);
          }
        }
      }})
      wx.login({
        success:(res)=> {
          console.log(res)
          wx.request({
            url: this.globalData.apiurl+'login',
            data:{
              code:res.code
            },
            success:(success)=>{
                console.log(success)
                if(success.data.code==0){
                  console.log(success.data.data)
                  this.globalData.user = success.data.data
                  if (this.emptyUserCallback) {
                    this.emptyUserCallback(this.globalData.user);
                  }
                }
            }
          })
        }
      })
  },
  
  onShow: function (options) {
      console.log('onshow')
  },
  globalData: {
    userInfo: null,
    apiurl:'https://api.sunhouse2002.com/agentApi/',
   // apiurl: 'http://127.0.0.1:8000/agentApi/',
    user:null,
    workshop_id:null,
  }
})